home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / test / testd.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  1.9 KB  |  65 lines  |  [TEXT/R*ch]

  1. (* This test works only for 32-bit implementations! *)
  2.  
  3. val maxint = 1073741823;
  4. val minint = ~maxint -1;
  5. infix seq
  6. fun e1 seq e2 = e2;
  7.  
  8. (~minint    seq "WRONG") handle Overflow => "OK";
  9. (abs minint seq "WRONG") handle Overflow => "OK";
  10. (maxint+1   seq "WRONG") handle Overflow => "OK";
  11. (minint-1   seq "WRONG") handle Overflow => "OK";
  12.  
  13. val sum = (op+) : int * int -> int;
  14. val diff = (op-) : int * int -> int;
  15. (sum (maxint,1)  seq "WRONG") handle Overflow => "OK";
  16. (diff (minint,1) seq "WRONG") handle Overflow => "OK";
  17.  
  18. (minint * ~1 seq  "WRONG") handle Overflow => "OK";
  19.  
  20. val prod = (op * ) : int * int -> int;
  21. (prod (minint,~1) seq "WRONG") handle Overflow => "OK";
  22.  
  23. fun checkDivMod i d =
  24.   let val q = i div d
  25.       val r = i mod d
  26.   in print i seq output(std_out, " "); print d seq output(std_out, "   ");
  27.      if (d * q + r = i) andalso
  28.         ((0 <= r andalso r < d) orelse (d < r andalso r <= 0))
  29.      then "OK" else "WRONG: problems with div, mod"
  30.   end;
  31.  
  32. checkDivMod 23 10;
  33. checkDivMod ~23 10;
  34. checkDivMod 23 ~10;
  35. checkDivMod ~23 ~10;
  36.  
  37. checkDivMod 100 10;
  38. checkDivMod ~100 10;
  39. checkDivMod 100 ~10;
  40. checkDivMod ~100 ~10;
  41.  
  42. checkDivMod 100 1;
  43. checkDivMod 100 ~1;
  44. checkDivMod 0 1;
  45. checkDivMod 0 ~1;
  46.  
  47. (100 div 0     seq  "WRONG") handle Div => "OK";
  48. (100 mod 0     seq  "WRONG") handle Div => "OK";
  49. (minint div ~1 seq  "WRONG") handle Overflow => "OK";
  50.  
  51. val maxri = real maxint;
  52. val minri = real minint;
  53.  
  54. if floor 3.0 = 3 then "OK" else "WRONG";
  55. if floor 3.14 = 3 then "OK" else "WRONG";
  56. if floor ~3.0 = ~3 then "OK" else "WRONG";
  57. if floor ~3.14 = ~4 then "OK" else "WRONG";
  58. if floor(maxri + 0.9) = maxint then "OK" else "WRONG";
  59. if floor minri = minint then "OK" else "WRONG";
  60. (floor (minri - 0.1) seq  "WRONG") handle Overflow => "OK";
  61. (floor (maxri + 1.0) seq  "WRONG") handle Overflow => "OK";
  62.  
  63. (sqrt ~10.0 seq  "WRONG") handle Sqrt => "OK";
  64. (ln 0.0     seq  "WRONG") handle Ln => "OK";
  65.